package com.pcitc.springbootmybatis.controller;

import com.pcitc.springbootmybatis.mapper.UserMapper;
import com.pcitc.springbootmybatis.model.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserMapper userMapper;

    @RequestMapping("/getUsers")
    public List<User> getUsers() {
        return userMapper.getAll();
    }

    @RequestMapping("/getUser/{id}")
    public User getUser(@PathVariable Long id){
        return userMapper.getOne(id);
    }

    @RequestMapping("/add/{user}")
    public void save(@PathVariable User user) {
        userMapper.insert(user);
    }

    @RequestMapping(value="update")
    public void update(User user) {
        userMapper.update(user);
    }

    @RequestMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        userMapper.delete(id);
    }

}
